package com.csthink.mr.inputformat;

import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author <a href="mailto:csthink@icloud.com">Mars</a>
 * @since 2024-04-15 10:55
 */
public class WebPermissionWritable implements Writable, DBWritable {

    private String id;

    private String permission;

    private String subPermission;

    private Integer displayOrder;

    public WebPermissionWritable() {
    }

    public WebPermissionWritable(String id, String permission, String subPermission, Integer displayOrder) {
        this.id = id;
        this.permission = permission;
        this.subPermission = subPermission;
        this.displayOrder = displayOrder;
    }

    @Override
    public String toString() {
        return id + "\t" + permission + "\t" + subPermission + "\t" + displayOrder;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(id);
        out.writeUTF(permission);
        out.writeUTF(subPermission);
        out.writeInt(displayOrder);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        this.id = in.readUTF();
        this.permission = in.readUTF();
        this.subPermission = in.readUTF();
        this.displayOrder = in.readInt();
    }

    @Override
    public void write(PreparedStatement statement) throws SQLException {

    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        this.id = resultSet.getString(1);
        this.permission = resultSet.getString(2);
        this.subPermission = resultSet.getString(3);
        this.displayOrder = resultSet.getInt(4);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public String getSubPermission() {
        return subPermission;
    }

    public void setSubPermission(String subPermission) {
        this.subPermission = subPermission;
    }

    public Integer getDisplayOrder() {
        return displayOrder;
    }

    public void setDisplayOrder(Integer displayOrder) {
        this.displayOrder = displayOrder;
    }


}
